home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / cycles / screens.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  19.1 KB  |  976 lines

  1.  
  2. #include <fmclient.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>    /* for exit */
  5. #include <string.h>    /* for strlen */
  6. #include <sys/times.h>    /* for times */
  7. #include <sys/param.h>    /* for times */
  8. #include <gl/device.h>
  9. #include "cycles.h"
  10. #include "sound.h"
  11.  
  12. fmfonthandle times_bold, bigfont, mediumfont, smallfont;
  13. extern CYCLE *good, bike[CYCLES];
  14. extern int solo, in_win, robot[CYCLES], trail_col[COLOURS];
  15. extern int audio, demo_mode;
  16. extern Matrix idmat;
  17. extern clock_t last_sent;
  18.  
  19. /* local prototypes */
  20. void plan_o_bike(void);
  21. void shaded_bg(void);
  22. void big_title_author(void);
  23. void small_title_author(void);
  24. short get_char(short c, char *, int );
  25. void draw_text_port_thing(char *, char *);
  26. void draw_title_screen(int);
  27. void draw_score_screen(int, int, int);
  28. void draw_buttons(int, int);
  29. int over_area(void);
  30. void draw_tic(void);
  31.  
  32. /* robin's wish is for a faster font library... or a faster 4D20 */
  33.  
  34.  
  35. void init_fonts(void) {
  36.     fminit();
  37.     if ( !(times_bold = fmfindfont("Times-Bold")) ) {
  38.     printf("couldn't find font family: Times-Bold\n");
  39.     exit(1);
  40.     }
  41. }
  42.  
  43.  
  44. void scale_fonts_to_win(void) {
  45.     long x, y;
  46.     static int last_y = 0;
  47.  
  48.     getsize(&x, &y);
  49.     if (last_y != y) {
  50.     bigfont    = fmscalefont(times_bold, 0.18*y);
  51.     mediumfont = fmscalefont(times_bold, 0.09*y);
  52.     smallfont  = fmscalefont(times_bold, 0.045*y);
  53.     last_y = y;
  54.     }
  55. }
  56.  
  57.  
  58. void shaded_bg(void) {
  59.     float v[3];
  60.  
  61.     bgnpolygon();
  62.     v[2] = -2.5;
  63. #ifdef RGB_MODE
  64.     cpack(0xffffff);
  65. #else
  66.     color(BLUE);
  67. #endif
  68.     v[0] = -2.0; v[1] = 1.0;
  69.     v3f(v);
  70. #ifdef RGB_MODE
  71.     cpack(0x0000ff);
  72. #endif
  73.     v[0] = 2.0; v[1] = 1.0;
  74.     v3f(v);
  75. #ifdef RGB_MODE
  76.     cpack(0xff0000);
  77. #endif
  78.     v[0] = 2.0; v[1] = -1.0;
  79.     v3f(v);
  80. #ifdef RGB_MODE
  81.     cpack(0x00ff00);
  82. #endif
  83.     v[0] = -2.0; v[1] = -1.0;
  84.     v3f(v);
  85.     endpolygon();
  86. }
  87.  
  88.  
  89. void big_title_author(void) {
  90. #ifdef RGB_MODE
  91.     cpack(0xffffff);
  92. #else
  93.     color(WHITE);
  94. #endif
  95.     cmov(-0.8, -0.5, -0.5);
  96.     fmsetfont(bigfont);
  97.     fmprstr("Cycles");
  98.  
  99. #ifdef RGB_MODE
  100.     cpack(0);
  101. #else
  102.     color(BLACK);
  103. #endif
  104.     fmsetfont(smallfont);
  105.     cmov(-1.3, -0.75, -0.5);
  106.     fmprstr("by Robin Humble, Alan Lipton and Nick Fitton");
  107. }
  108.  
  109.  
  110. void small_title_author(void) {
  111. #ifdef RGB_MODE
  112.     cpack(0xffffff);
  113. #else
  114.     color(WHITE);
  115. #endif
  116.     cmov(0.6, -0.3, -0.5);
  117.     fmsetfont(mediumfont);
  118.     fmprstr("Cycles");
  119.  
  120. #ifdef RGB_MODE
  121.     cpack(0);
  122. #else
  123.     color(BLACK);
  124. #endif
  125.     fmsetfont(smallfont);
  126.     cmov(0.1, -0.5, -0.5);
  127.     fmprstr("by Robin Humble, Alan Lipton");
  128.     cmov(0.6, -0.65, -0.5);
  129.     fmprstr("and Nick Fitton");
  130. }
  131.  
  132.  
  133. /*
  134.  * draw plan view style thing of bike
  135.  */
  136. void plan_o_bike(void) {
  137.     pushmatrix();
  138.  
  139.     translate(0.0, 0.0, -10.0);
  140.  
  141.     pushmatrix();
  142.     rot(90.0, 'y');
  143.     /* these are: id, rot, colour, lo_res, robot, robot flag colour */
  144.     draw_cycle(0, 0.0, 5, 0, 0, 0);
  145.     popmatrix();
  146.  
  147.     pushmatrix();
  148.     translate(3.0, 0.0, 0.0);
  149.     rot(210.0, 'y');
  150.     draw_cycle(0, 0.0, 4, 0, 0, 0);
  151.     popmatrix();
  152.  
  153.     popmatrix();
  154. }
  155.  
  156.  
  157. /*
  158.  * more or less from 4Dgifts prompt.c:
  159.  * get a char from the keyboard and add it to the name string
  160.  */
  161. short get_char(short c, char *name, int maxlen) {
  162.     int ptr;
  163.  
  164.     ptr = strlen(name);
  165.     if (ptr == 0) name[0] = '\0';
  166.  
  167.     switch(c) {
  168.     case '\027':        /* ^W or ^U sets cursor back to start */
  169.     case '\025':
  170.         name[0] = '\0';
  171.         break;
  172.     case '\n':
  173.     case '\r':
  174.         return(c);
  175.     case '\b':
  176.         if (ptr) name[--ptr] = '\0';
  177.         break;
  178.     default:
  179.         if (ptr < (maxlen -1)) {
  180.         name[ptr++] = c;
  181.         name[ptr] = '\0';
  182.         }
  183.         break;
  184.     }
  185.     return(c);
  186. }
  187.  
  188.  
  189. void draw_text_port_thing(char *prompt, char *data) {
  190. #ifdef RGB_MODE
  191.     cpack(0xffffff);
  192. #else
  193.     color(WHITE);
  194. #endif
  195.     pushmatrix();
  196.     translate(0.0, 0.0, -0.5);
  197.     rectf(-1.9, -0.95, 0.0, -0.75);
  198. #ifdef RGB_MODE
  199.     cpack(0);
  200. #else
  201.     color(BLACK);
  202. #endif
  203.     linewidth(2);
  204.     rect(-1.9, -0.95, 0.0, -0.75);
  205.     linewidth(1);
  206.     popmatrix();
  207.  
  208. #ifdef RGB_MODE
  209.     cpack(0);
  210. #else
  211.     color(BLACK);
  212. #endif
  213.     fmsetfont(smallfont);
  214.     cmov(-1.8, -0.88, -0.5);
  215.     fmprstr(prompt);
  216. #ifdef RGB_MODE
  217.     cpack(0xff0000);
  218. #else
  219.     color(BLUE);
  220. #endif
  221.     cmov(-1.4, -0.88, -0.5);
  222.     fmprstr(data);
  223. }
  224.  
  225.  
  226. void draw_tic(void) {
  227.     float v[2];
  228. #ifdef RGB_MODE
  229.     cpack(0x0000ff);
  230. #else
  231.     color(RED);
  232. #endif
  233.     bgntmesh();
  234.     v[0] = -0.9; v[1] = -0.1; v2f(v);
  235.     v[0] = -0.7; v[1] =  0.4; v2f(v);
  236.     v[0] =  0.0; v[1] = -0.7; v2f(v);
  237.     v[0] =  0.0; v[1] =  0.0; v2f(v);
  238.     v[0] =  1.0; v[1] =  0.9; v2f(v);
  239.     v[0] =  0.8; v[1] =  1.0; v2f(v);
  240.     v[0] =  1.4; v[1] =  1.3; v2f(v);
  241.     endtmesh();    
  242. }
  243.  
  244. float but[10][2] = {{0.9, 1.1}, /* network */
  245.             {1.7, 0.4}, /* colours random button */
  246.             {1.3, 0.6}, /* colours... */
  247.             {1.5, 0.6},
  248.             {1.7, 0.6},
  249.             {1.3, 0.8},
  250.             {1.5, 0.8},
  251.             {1.7, 0.8},
  252.             {0.9, 0.9}, /* demo mode button */
  253.             {0.9, 1.3} }; /* audio mode button */
  254.  
  255. void draw_buttons(int colour_choice, int num_robots) {
  256.     float v[2];
  257.     int i;
  258.     char junk[32];
  259.  
  260.     pushmatrix();
  261.     translate(-2.0, -1.0, -0.5);
  262.     /* coords 0->2 in x, 0->1 in y */
  263.  
  264.     linewidth(2);
  265.     /* network button */
  266. #ifdef RGB_MODE
  267.     cpack(0xffffff);
  268. #else
  269.     color(WHITE);
  270. #endif
  271.     circf(but[0][0], but[0][1], 0.08);
  272. #ifdef RGB_MODE
  273.     cpack(0);
  274. #else
  275.     color(BLACK);
  276. #endif
  277.     circ(but[0][0], but[0][1], 0.08);
  278.     if (!solo) {
  279.     /* draw tic */
  280.     pushmatrix();
  281.     translate(but[0][0] - 0.02, but[0][1] - 0.02, 0.0);
  282.     scale(0.06, 0.06, 1.0);
  283.     draw_tic();
  284.     popmatrix();
  285.     }
  286.  
  287.     /* audio button */
  288. #ifdef AUDIO
  289. #ifdef RGB_MODE
  290.     cpack(0xffffff);
  291. #else
  292.     color(WHITE);
  293. #endif
  294.     circf(but[9][0], but[9][1], 0.08);
  295. #ifdef RGB_MODE
  296.     cpack(0);
  297. #else
  298.     color(BLACK);
  299. #endif
  300.     circ(but[9][0], but[9][1], 0.08);
  301.     if (audio) {
  302.     /* draw tic */
  303.     pushmatrix();
  304.     translate(but[9][0] - 0.02, but[9][1] - 0.02, 0.0);
  305.     scale(0.06, 0.06, 1.0);
  306.     draw_tic();
  307.     popmatrix();
  308.     }
  309. #endif
  310.  
  311.     /* demo mode button */
  312. #ifdef RGB_MODE
  313.     cpack(0xffffff);
  314. #else
  315.     color(WHITE);
  316. #endif
  317.     circf(but[8][0], but[8][1], 0.08);
  318. #ifdef RGB_MODE
  319.     cpack(0);
  320. #else
  321.     color(BLACK);
  322. #endif
  323.     circ(but[8][0], but[8][1], 0.08);
  324.     if (demo_mode) {
  325.     /* draw tic */
  326.     pushmatrix();
  327.     translate(but[8][0] - 0.02, but[8][1] - 0.02, 0.0);
  328.     scale(0.06, 0.06, 1.0);
  329.     draw_tic();
  330.     popmatrix();
  331.     }
  332.  
  333.     /* left arrow */
  334. #ifdef RGB_MODE
  335.     cpack(0xffffff);
  336. #else
  337.     color(WHITE);
  338. #endif
  339.     bgntmesh();
  340.     v[0] = 0.1; v[1] = 0.4; v2f(v);
  341.     v[0] = 0.3; v[1] = 0.3; v2f(v);
  342.     v[0] = 0.3; v[1] = 0.5; v2f(v);
  343.     endtmesh();
  344. #ifdef RGB_MODE
  345.     cpack(0);
  346. #else
  347.     color(BLACK);
  348. #endif
  349.     bgnclosedline();
  350.     v[0] = 0.1; v[1] = 0.4; v2f(v);
  351.     v[0] = 0.3; v[1] = 0.3; v2f(v);
  352.     v[0] = 0.3; v[1] = 0.5; v2f(v);
  353.     endclosedline();
  354.  
  355.     /* right arrow */
  356. #ifdef RGB_MODE
  357.     cpack(0xffffff);
  358. #else
  359.     color(WHITE);
  360. #endif
  361.     bgntmesh();
  362.     v[0] = 0.9; v[1] = 0.4; v2f(v);
  363.     v[0] = 0.7; v[1] = 0.3; v2f(v);
  364.     v[0] = 0.7; v[1] = 0.5; v2f(v);
  365.     endtmesh();
  366. #ifdef RGB_MODE
  367.     cpack(0);
  368. #else
  369.     color(BLACK);
  370. #endif
  371.     bgnclosedline();
  372.     v[0] = 0.9; v[1] = 0.4; v2f(v);
  373.     v[0] = 0.7; v[1] = 0.3; v2f(v);
  374.     v[0] = 0.7; v[1] = 0.5; v2f(v);
  375.     endclosedline();
  376.     /* box between */
  377. #ifdef RGB_MODE
  378.     cpack(GREY50);
  379. #else
  380.     color(GREY50);
  381. #endif
  382.     rectf(0.33, 0.28, 0.67, 0.52);
  383.  
  384.     /* colour shape */
  385.     for (i = 0; i < COLOURS; i++) {
  386. #ifdef RGB_MODE
  387.     cpack(trail_col[i]);
  388. #else
  389.     color(trail_col[i]);
  390. #endif
  391.     circf(but[i+2][0], but[i+2][1], 0.08);
  392.     if (i == colour_choice)
  393. #ifdef RGB_MODE
  394.         cpack(0xffffff);
  395.     else
  396.         cpack(0);
  397. #else
  398.         color(WHITE);
  399.     else
  400.         color(BLACK);
  401. #endif
  402.     circ(but[i+2][0], but[i+2][1], 0.08);
  403.     }
  404.     /* and random box */
  405. #ifdef RGB_MODE
  406.     cpack(0xffffff);
  407. #else
  408.     color(WHITE);
  409. #endif
  410.     circf(but[1][0], but[1][1], 0.08);
  411. #ifdef RGB_MODE
  412.     cpack(0);
  413. #else
  414.     color(BLACK);
  415. #endif
  416.     circ(but[1][0], but[1][1], 0.08);
  417.     if (colour_choice == -1) {
  418.     pushmatrix();
  419.     translate(but[1][0] - 0.02, but[1][1] - 0.02, 0.0);
  420.     scale(0.06, 0.06, 1.0);
  421.     draw_tic();
  422.     popmatrix();
  423.     }
  424.  
  425.     linewidth(1);
  426.  
  427.     /* text */
  428. #ifdef RGB_MODE
  429.     cpack(0xffffff);
  430. #else
  431.     color(WHITE);
  432. #endif
  433.     fmsetfont(smallfont);
  434.     cmov2(0.25, 1.05);
  435.     fmprstr("network");
  436. #ifdef AUDIO
  437.     cmov2(0.25, 1.25);
  438.     fmprstr("audio");
  439. #endif
  440.     cmov2(0.1, 0.85);
  441.     fmprstr("demo mode");
  442.     cmov2(0.2, 0.55);
  443.     fmprstr("your robots");
  444.     cmov2(1.1, 0.35);
  445.     fmprstr("random");
  446.     cmov2(1.3, 1.0);
  447.     fmprstr("colours");
  448.     fmsetfont(mediumfont);
  449.     cmov2(0.35, 0.31);
  450.     sprintf(junk, "%d", num_robots);
  451.     fmprstr(junk);
  452. #ifdef RGB_MODE
  453.     cpack(0xff0000);
  454. #else
  455.     color(BLUE);
  456. #endif
  457.     cmov2(0.15, 1.6);
  458.     fmprstr("Options");
  459.  
  460.     popmatrix();
  461. }
  462.  
  463.  
  464. /*
  465.  * area 0: solo/network toggle
  466.  * area 1: rand colours
  467.  * area 2-7: colours
  468.  * area 8: demo button
  469.  * area 9: audio on/off
  470.  * area 10: robots++
  471.  * area 11: robots--
  472.  */
  473. int over_area(void) {
  474.     int i;
  475.     long xm, ym, xo, yo, xs, ys;
  476.     float x, y, dx, dy;
  477.  
  478.     xm = getvaluator(MOUSEX);
  479.     ym = getvaluator(MOUSEY);
  480.  
  481.     /* scale x, y to window */
  482.     getorigin(&xo, &yo);
  483.     getsize(&xs, &ys);
  484.     x = (float)(xm - xo)/(float)xs;
  485.     y = (float)(ym - yo)/(float)ys;
  486.  
  487.     /* coords -2->0 in x, -1->0 in y */
  488.     /* translate(-2.0, -1.0, -0.5);  */
  489.     /* coords  0->2 in x,  0->1 in y */
  490.     x *= 4.0;
  491.     y *= 2.0;
  492.  
  493.     /* do circular buttons */
  494.     for (i = 0; i < 10; i++) {
  495.     dx = but[i][0] - x;
  496.     dy = but[i][1] - y;
  497.     if (dx*dx + dy*dy < 0.08*0.08) return (i);
  498.     }
  499.  
  500.     /* left arrow */
  501.     if (x < 0.3 && y < 0.35+0.5*x && y > 0.45-0.5*x) return(10);
  502.     /* right arrow */
  503.     if (x > 0.7 && y < 0.85-0.5*x && y > -0.05+0.5*x) return(11);
  504.  
  505.     return(-1);
  506. }
  507.  
  508.  
  509. void draw_title_screen(int screen_num) {
  510.     zclear();
  511.  
  512.     zbuffer(FALSE);
  513.     if (screen_num == 0 || screen_num == 1)
  514.     shaded_bg();
  515.     else {
  516. #ifdef RGB_MODE
  517.     cpack(GREY50);
  518. #else
  519.     color(GREY50);
  520. #endif
  521.     clear();
  522.     }
  523.  
  524.     /* draw a bike to start with */
  525.     if (screen_num != 4) {
  526.     zbuffer(TRUE);
  527.     pushmatrix();
  528.     if (screen_num == 3) {
  529.         translate(0.75, 0.15, 0.0);
  530.         scale(0.15, 0.15, 0.15);
  531.     }
  532.     else if (screen_num == 2) {
  533.         translate(1.3, 0.6, 0.0);
  534.         scale(0.07, 0.07, 0.07);
  535.     }
  536.     else
  537.         scale(0.2, 0.2, 0.2);
  538.     plan_o_bike();
  539.     popmatrix();
  540.     zbuffer(FALSE);
  541.     }
  542.  
  543.     /* draw text if the fonts have scaled... */
  544.     if (screen_num == 0) {
  545. #ifdef RGB_MODE
  546.     cpack(0);
  547. #else
  548.     color(BLACK);
  549. #endif
  550.     cmov(1.0, -0.9, -0.5);
  551.     charstr("initialising...");
  552.     }
  553.     else if (screen_num == 1) {
  554.     big_title_author();
  555. #ifdef RGB_MODE
  556.     cpack(0xffffff);
  557. #else
  558.     color(WHITE);
  559. #endif
  560.     cmov(-1.0, -0.9, -0.5);
  561.     fmprstr("Return to Continue     ESC to exit");
  562.     }
  563.     else if (screen_num == 2) {
  564. #ifdef RGB_MODE
  565.     cpack(0xffffff);
  566. #else
  567.     color(WHITE);
  568. #endif
  569.     fmsetfont(bigfont);
  570.     cmov(-1.0, 0.6, -0.5);
  571.     fmprstr("Cycles");
  572. #ifdef RGB_MODE
  573.     cpack(0);
  574. #else
  575.     color(BLACK);
  576. #endif
  577.     fmsetfont(smallfont);
  578.     cmov(-1.5, 0.3, -0.5);
  579.     fmprstr("You are riding your cycle against humans and");
  580.     cmov(-1.5, 0.15, -0.5);
  581.     fmprstr("hunter killer robots. Avoid hitting all bike trails.");
  582.     cmov(-1.5, 0.0, -0.5);
  583.     fmprstr("Points are awarded for excessive speed and making");
  584.     cmov(-1.5, -0.15, -0.5);
  585.     fmprstr("others crash near you or run into your trail.");
  586.     cmov(-1.5, -0.3, -0.5);
  587.     fmprstr("           Really politically correct huh?");
  588.     cmov(-1.5, -0.45, -0.5);
  589.     fmprstr("Look for holes through to other levels, however");
  590.     cmov(-1.5, -0.6, -0.5);
  591.     fmprstr("only you can see your holes ... and they move!");
  592.  
  593. #ifdef RGB_MODE
  594.     cpack(0xffffff);
  595. #else
  596.     color(WHITE);
  597. #endif
  598.     cmov(-1.0, -0.9, -0.5);
  599.     fmprstr("Return to Continue     ESC to exit");
  600.     }
  601.     else if (screen_num == 3) {
  602.     small_title_author();
  603. #ifdef RGB_MODE
  604.     cpack(0xffffff);
  605. #else
  606.     color(WHITE);
  607. #endif
  608.     cmov(0.2, -0.85, -0.5);
  609.     fmprstr("Enter Data and Press Return");
  610.     }
  611.     else if (screen_num == 4) {
  612. #ifdef RGB_MODE
  613.     cpack(0xff0000);
  614. #else
  615.     color(BLUE);
  616. #endif
  617.     fmsetfont(mediumfont);
  618.     cmov(-0.5, 0.7, -0.5);
  619.     fmprstr("Help");
  620. #ifdef RGB_MODE
  621.     cpack(0xffff00);
  622. #else
  623.     color(CYAN);
  624. #endif
  625.     /* duplicated from instructions() */
  626.     fmsetfont(smallfont);
  627.     cmov(-1.2, 0.3, -0.5);
  628.     fmprstr("turn  - left and right mouse buttons");
  629.     cmov(-1.2, 0.15, -0.5);
  630.     fmprstr("speed - hold down A or middle mouse to");
  631.     cmov(-1.2, 0.0, -0.5);
  632.     fmprstr("             accelerate. lift off to slow down");
  633.     cmov(-1.2, -0.15, -0.5);
  634.     fmprstr("jump  - space bar\n");
  635.     cmov(-1.2, -0.3, -0.5);
  636.     fmprstr("look  - use left and right arrows to look around");
  637.     cmov(-1.2, -0.45, -0.5);
  638.     fmprstr("help  - H toggles instructions");
  639.     cmov(-1.2, -0.6, -0.5);
  640.     fmprstr("quit  - ESC key");
  641.  
  642.     cmov(0.0, -0.8, -0.5);
  643. #ifdef RGB_MODE
  644.     cpack(0xffffff);
  645. #else
  646.     color(WHITE);
  647. #endif
  648.     fmprstr("Press Return to Continue");
  649.     }
  650.     else if (screen_num == 5) {
  651.     cmov(0.0, -0.8, -0.5);
  652. #ifdef RGB_MODE
  653.     cpack(0x0000ff);
  654. #else
  655.     color(RED);
  656. #endif
  657.     fmprstr("Networking to Game...");
  658.     }
  659.     zbuffer(TRUE);
  660. }
  661.  
  662.  
  663. /*
  664.  * title screens:
  665.  *
  666.  *  screen 0 is bikes + waiting
  667.  *  screen 1 is bikes + titles + press key
  668.  *  screen 2 is instructions
  669.  *  screen 3 is small bikes + intro + data entry
  670.  *  screen 4 is help
  671.  *  screen 5 is screen 4 + starting network message
  672.  */
  673. void title_screen(int screen_num, char *name, int *colour_choice, int *num_robots) {
  674.     int exit_now, key;
  675.     short val, c;
  676.  
  677.  
  678.     exit_now = 0;
  679.     qdevice(RETKEY);
  680.  
  681.     if (screen_num == 0 || screen_num == 5)
  682.     exit_now = 1;   /* no looping if screen 0 */
  683.     else if (screen_num == 3)
  684.     qdevice(KEYBD);
  685.  
  686.     loadmatrix(idmat);
  687.     ortho(-2.0, 2.0, -1.0, 1.0, 0.1, 3.0);
  688.  
  689.     draw_title_screen(screen_num);
  690.     if (screen_num == 3) {
  691.     draw_buttons(*colour_choice, *num_robots);
  692.     draw_text_port_thing("Name:", name);
  693.     }
  694.     swapbuffers();
  695.     /* draw again for textport */
  696.     if (screen_num == 3) {
  697.     draw_title_screen(screen_num);
  698.     draw_buttons(*colour_choice, *num_robots);
  699.     draw_text_port_thing("Name:", name);
  700.     swapbuffers();
  701.     }
  702.  
  703.     do {
  704.     if (screen_num != 0 && screen_num != 5) {
  705.         switch(qread(&val)) {
  706.         case INPUTCHANGE:
  707.             in_win = val % 256;        /* % for dgl stuff */
  708.             break;
  709.         case REDRAW:
  710.             reshapeviewport();
  711.             scale_fonts_to_win();
  712.             draw_title_screen(screen_num);
  713.             if (screen_num == 3) {
  714.             draw_buttons(*colour_choice, *num_robots);
  715.             draw_text_port_thing("Name:", name);
  716.             }
  717.             swapbuffers();
  718.             /* draw again for textport */
  719.             if (screen_num == 3) {
  720.             draw_title_screen(screen_num);
  721.             draw_buttons(*colour_choice, *num_robots);
  722.             draw_text_port_thing("Name:", name);
  723.             swapbuffers();
  724.             }
  725.             break;
  726.         case ESCKEY:
  727.             exit(0);
  728.             break;
  729.         case KEYBD:
  730.             if (screen_num == 3 && val) {
  731.             c = get_char(val, name, NAME_SIZE);
  732.             if (c == '\n' || c == '\r') exit_now = 1;
  733.             draw_buttons(*colour_choice, *num_robots);
  734.             draw_text_port_thing("Name:", name);
  735.             swapbuffers();
  736.             }
  737.             break;
  738.         case RETKEY:
  739.             if (val && screen_num != 3)
  740.             exit_now = 1;
  741.             break;
  742.         case LEFTMOUSE:
  743.             if (val && screen_num != 3)
  744.             exit_now = 1;
  745.             else if (val && screen_num == 3) {
  746.             switch (key = over_area()) {
  747.                 case 0:
  748.                 if (solo)
  749.                     solo = 0;
  750.                 else
  751.                     solo = 1;
  752.                 break;
  753.                 case 1: /* random button */
  754.                 case 2:
  755.                 case 3:
  756.                 case 4:
  757.                 case 5:
  758.                 case 6:
  759.                 case 7:
  760.                 *colour_choice = key - 2;
  761.                 break;
  762.                 case 8:
  763.                 if (demo_mode)
  764.                     demo_mode = 0;
  765.                 else
  766.                     demo_mode = 1;
  767.                 break;
  768.                 case 9:
  769. #ifdef AUDIO
  770.                 if (audio)
  771.                     audio = 0;
  772.                 else
  773.                     audio = 1;
  774. #else
  775.                 audio = 0;
  776. #endif
  777.                 break;
  778.                 case 10:
  779.                 (*num_robots)--;
  780.                 if (*num_robots < 0) *num_robots = 0;
  781.                 break;
  782.                 case 11:
  783.                 (*num_robots)++;
  784.                 if (*num_robots > CYCLES-1) *num_robots = CYCLES-1;
  785.                 break;
  786.             }
  787.             draw_buttons(*colour_choice, *num_robots);
  788.             draw_text_port_thing("Name:", name);
  789.             swapbuffers();
  790.             }
  791.             break;
  792.         default:
  793.             break;
  794.         }
  795.     }
  796.     } while (!exit_now);
  797.  
  798.     unqdevice(RETKEY);
  799.     if (screen_num == 3) unqdevice(KEYBD);
  800.  
  801.     /* restore coords */
  802.     set_win_coords();
  803. }
  804.  
  805.  
  806. /*
  807.  * draw a current score screen
  808.  */
  809. void draw_score_screen(int pts, int big_kills, int trail_kills) {
  810.     char junk[64];
  811.  
  812. #ifdef RGB_MODE
  813.     cpack(GREY50);
  814. #else
  815.     color(GREY25);
  816. #endif
  817.     zclear();
  818.     clear();
  819.  
  820.     /* draw bikes as background */
  821.     pushmatrix();
  822.     translate(0.6, 0.2, 0.0);
  823.     scale(0.1, 0.1, 0.1);
  824.     plan_o_bike();
  825.     popmatrix();
  826.  
  827.     zbuffer(FALSE);
  828.  
  829.     /* write up our score */
  830. #ifdef RGB_MODE
  831.     cpack(0xff0000);
  832. #else
  833.     color(BLUE);
  834. #endif
  835.     fmsetfont(mediumfont);
  836.     cmov2(0.02, 0.8);
  837.     fmprstr(good->name);
  838.  
  839. #ifdef RGB_MODE
  840.     cpack(0xffffff);
  841. #else
  842.     color(WHITE);
  843. #endif
  844.     cmov2(0.02, 0.2);
  845.     sprintf(junk, "games %d  average score %d",
  846.       good->games, (int)((float)good->pts/(float)good->games));
  847.     fmprstr(junk);
  848. #ifdef RGB_MODE
  849.     cpack(0x00ff00);
  850. #else
  851.     color(GREEN);
  852. #endif
  853.     cmov2(0.02, 0.4);
  854.     sprintf(junk, "game points %d", pts);
  855.     fmprstr(junk);
  856.  
  857. #ifdef RGB_MODE
  858.     cpack(0x0000ff);
  859. #else
  860.     color(RED);
  861. #endif
  862.     cmov2(0.02, 0.6);
  863.     sprintf(junk, "kills %d trails %d", big_kills, trail_kills);
  864.     fmprstr(junk);
  865.  
  866.     fmsetfont(smallfont);
  867. #ifdef RGB_MODE
  868.     cpack(0xffffff);
  869. #else
  870.     color(WHITE);
  871. #endif
  872.     cmov2(0.2, 0.05);
  873.     fmprstr("Press Return to Continue     ESC to exit");
  874.  
  875.     pushmatrix();
  876.     translate(0.75, 0.55, 0.0);
  877.     scale(0.15/DIM, -0.3/DIM, 0.0);
  878.     draw_all_2d();
  879.     popmatrix();
  880.  
  881.     write_player_list(0.4, 0.95, -0.03);
  882.  
  883.     zbuffer(TRUE);
  884. }
  885.  
  886.  
  887. void score_screen(int pts, int big_kills, int trail_kills) {
  888.     int i, exit_now;
  889.     short val;
  890.     struct tms t;
  891.  
  892.     scale_fonts_to_win();
  893.     loadmatrix(idmat);
  894.     ortho2(0.0, 1.0, 0.0, 1.0);
  895.  
  896.     exit_now = 0;
  897.     qdevice(RETKEY);
  898.  
  899.     scale_fonts_to_win();
  900.     draw_score_screen(pts, big_kills, trail_kills);
  901.     swapbuffers();
  902.  
  903.     do {
  904.     if (qtest()) {
  905.         switch(qread(&val)) {
  906.         case INPUTCHANGE:
  907.             in_win = val % 256;        /* % for dgl stuff */
  908.             break;
  909.         case REDRAW:
  910.             reshapeviewport();
  911.             scale_fonts_to_win();
  912.             break;
  913.         case ESCKEY:
  914.             good->quit = 1;    /* NOTE: this is in main loop and search_for_exit also */
  915.             for (i = 0; i < CYCLES; i++)
  916.             if (robot[i]) bike[i].quit = 1;
  917.             if (!solo) send_update_mcast();
  918. #ifdef AUDIO
  919.             if (audio) close_audio();
  920. #endif
  921.             exit(0);
  922.             break;
  923.         case RETKEY:
  924.         case LEFTMOUSE:
  925.             if (val) exit_now = 1;
  926.             break;
  927.         default:
  928.             break;
  929.         }
  930.     }
  931.  
  932.     set_speed_fac(0);
  933.  
  934.     for (i = 0; i < CYCLES; i++)
  935.         if (robot[i] && bike[i].falling == 0)
  936.         move_cycles(&bike[i]);
  937.  
  938.     move_our_robots();
  939.  
  940.     /* handle network events */
  941.     if (!solo) {
  942.         if (get_and_sort_mcasts() || last_sent + NET_TIMEOUT*HZ < times(&t))
  943.         send_all_full_mcast();
  944.         else
  945.         send_update_mcast();
  946.         last_sent = times(&t);
  947.     
  948.         /* kill off any cycles that aren't talking any more */
  949.         kill_dead_cycle();
  950.     }
  951.  
  952. #ifdef DEBUG
  953. printf("\n");
  954. printf("screens: robot: \n");
  955. { int i; for (i=0;i<CYCLES;i++) printf("%d ", robot[i]); }
  956. printf("\n");
  957. printf("screens: used: \n");
  958. { int i; extern int used[CYCLES]; for (i=0;i<CYCLES;i++) printf("%d ", used[i]); }
  959. printf("\n");
  960. printf("screens: players: \n");
  961. { int i; extern int used[CYCLES]; for (i=0;i<CYCLES;i++) if (used[i]) printf("%d: %s aliv? %d fall %g   ",
  962.  bike[i].id, bike[i].name, bike[i].alive, bike[i].fall); }
  963. printf("\n");
  964. #endif
  965.  
  966.     draw_score_screen(pts, big_kills, trail_kills);
  967.     swapbuffers();
  968.  
  969.     } while (!exit_now);
  970.  
  971.     unqdevice(RETKEY);
  972.  
  973.     /* restore coords */
  974.     set_win_coords();
  975. }
  976.